/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sgt.supermarket.hibernatedao;

import java.util.Date;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import sgt.supermarket.entity.Invoice;

/**
 *
 * @author THUY TUNG
 */
public class HibernateInvoiceDAO extends HibernateGenericDAO<Invoice, Long> {

    public HibernateInvoiceDAO(Session session) {
        super(session);
    }

    public List<Invoice> getByCustomerId(long customerAutoId) {
        return getSession().createCriteria(Invoice.class).add(Expression.eq("customer.autoId", customerAutoId)).list();
    }

    public List<Invoice> getByDate(Date date) {
        return getSession().createCriteria(Invoice.class).add(Expression.eq("createdDate", date)).list();
    }

    public List<Date> getDistinctDates() {
        return getSession().createQuery("select distinct invoice.createdDate from Invoice invoice").list();
    }
}
